#
# @lc app=leetcode.cn id=98 lang=python3
#
# [98] 验证二叉搜索树
#

# @lc code=start
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def isValidBST(self, root: TreeNode) -> bool:
        def isValidBST(root: TreeNode, min: TreeNode, max: TreeNode):
            if root is None:
                return True

            if min is not None and root.val <= min.val:
                return False
            if max is not None and root.val >= max.val:
                return False

            return isValidBST(root.left, min, root) and isValidBST(root.right, root, max)
            
        return isValidBST(root, None, None)
# @lc code=end
